package com.bw.paper.mvp.view.news.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bw.paper.R;
import com.bw.paper.mvp.model.entity.NewsEntity;
import com.bw.paper.network.Api;
import com.bw.paper.network.LoadImage;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

public class ImageBannerAdapter extends PagerAdapter {

    private List<NewsEntity.Values>list;

    public ImageBannerAdapter(List<NewsEntity.Values>list){
        this.list = list;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        View view = (View) object;
        container.removeView(view);
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_news_banner,container,false);
        container.addView(view);
        String url = list.get(position).getMedias().get(0).media_url;
        ImageView img = view.findViewById(R.id.news_banner_img);
        LoadImage.loadMatchImg(url,img);
        return view;
    }
}
